<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;

class SendEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $email,$template,$subject;

    /**
     * Create a new job instance.
     *
     * @param $email
     * @param $template
     * @param $subject
     */
    public function __construct($email, $template,$subject)
    {
        $this->email=$email;
        $this->template=$template;
        $this->subject=$subject;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $data=[
            'email'=>$this->email,
            'subject'=>$this->subject
        ];
        Log::info('email info',$data);
        Mail::send($this->template, $data, function($message) use($data)
        {
            $message->to($data['email'], $data['email'])->from()->subject($data['subject']);
        });
    }
}
